package com.sskj.one.login;

import android.content.Context;
import android.content.Intent;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.hjq.toast.ToastUtils;
import com.sskj.common.util.CheckUtil;
import com.sskj.common.util.ClickUtil;
import com.sskj.lib.base.BaseActivity;
import com.sskj.one.R;
import com.sskj.one.util.EditUtil;

import butterknife.BindView;

/**
 * @author Hey
 * Create at  2019/05/21
 */
public class ForgetPwdActivity extends BaseActivity<ForgetPwdPresenter> {


    @BindView(R.id.iv_close)
    ImageView ivClose;
    @BindView(R.id.et_mobile)
    EditText etMobile;
    @BindView(R.id.et_code)
    EditText etCode;
    @BindView(R.id.tv_get_code)
    TextView tvGetCode;
    @BindView(R.id.et_pwd)
    EditText etPwd;
    @BindView(R.id.iv_see)
    ImageView ivSee;
    @BindView(R.id.et_pwd_again)
    EditText etPwdAgain;
    @BindView(R.id.iv_see_again)
    ImageView ivSeeAgain;
    @BindView(R.id.btn_confirm)
    Button btnConfirm;

    @Override
    public int getLayoutId() {
        return R.layout.app_activity_forget_pwd;
    }

    @Override
    public ForgetPwdPresenter getPresenter() {
        return new ForgetPwdPresenter();
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {


    }

    @Override
    protected void initEvent() {
        ClickUtil.click(300, ivClose, this::finish);
        ClickUtil.click(300, ivSee, () -> EditUtil.togglePs(etPwd, ivSee));
        ClickUtil.click(300, ivSeeAgain, () -> EditUtil.togglePs(etPwdAgain, ivSeeAgain));
        ClickUtil.click(300, tvGetCode, () -> {
            if (isEmpty(etMobile)) {
                toastHint(etMobile);
                return;
            }
            if (!CheckUtil.isMobile(getText(etMobile))) {
                ToastUtils.show("手机号格式错误");
                return;
            }
            mPresenter.getSMSCode(getText(etMobile));
        });
        ClickUtil.click(300,btnConfirm,() -> {
            if (isEmpty(etMobile)) {
                toastHint(etMobile);
                return;
            }
            if (!CheckUtil.isMobile(getText(etMobile))) {
                ToastUtils.show("手机号格式错误");
                return;
            }
            if (isEmpty(etCode)) {
                toastHint(etCode);
                return;
            }
            if (isEmpty(etPwd)) {
                toastHint(etPwd);
                return;
            }
            if (!CheckUtil.isPayPwd(getText(etPwd))) {
                toastHint(etPwd);
                return;
            }
            if (isEmpty(etPwdAgain)) {
                toastHint(etPwdAgain);
                return;
            }
            if (!getText(etPwd).equals(getText(etPwdAgain))) {
                ToastUtils.show("两次密码输入不一致");
                return;
            }
            mPresenter.forgetLogin(getText(etMobile)
                    , getText(etCode)
                    , getText(etPwd)
                    , getText(etPwdAgain));
        });
    }

    public void getCodeOK() {
        startTimeDown(tvGetCode);
    }


    public static void start(Context context) {
        Intent intent = new Intent(context, ForgetPwdActivity.class);
        context.startActivity(intent);
    }
}
